package com.itita.ww2.model.user.battle;

import com.itita.ww2.model.user.UserProfile;
import com.smartfoxserver.v2.entities.data.ISFSObject;

@SuppressWarnings("unused")
public class MissionBattleState extends BaseBattleState {
	// private static final Logger logger = LoggerFactory.getLogger(MissionBattleState.class);
	// 
	private int blockId;
	private int cityId;
	private String missionId;

	private boolean isFirst; // 首次战斗

	public MissionBattleState(UserProfile userProfile, ISFSObject lastDeployArmy, int blockId, int cityId,
			String missionId) {
		super(userProfile);
		setLastDeployArmy(lastDeployArmy);
		this.blockId = blockId;
		this.cityId = cityId;
		this.missionId = missionId;
		this.battleType = BattleType.Mission;
		// 掉线不扣兵
		this.offlineSubArmy = false;
		this.isFirst = false;
	}

	@Override
	public void startBattle() {
		super.startBattle();
	}

	@Override
	public void endBattle(boolean online, boolean victory) {
		if (online) {
			if (victory) {
				// 引导前3关自动设定step
				int tempStep = userProfile.getUserInfo().getGuideStep();
				switch (tempStep) {
				case 0:
				case 3:
				case 9:
					userProfile.getUserInfo().setGuideStep(tempStep + 1);
					userProfile.getUserInfo().syncGuideStep();
					break;
				}
			}
			//			else {
			//				// 存在兵种限制的关卡首次失败不扣兵
			//				boolean limit = MissionConfig.isArmyLimit(missionId);
			//				if (isFirst && limit) {
			//					return;
			//				}
			//			}
			super.endBattle(online, victory);
		} else {
			super.endBattle(online, false);
		}
	}

	public int getBlockId() {
		return blockId;
	}

	public int getCityId() {
		return cityId;
	}

	public String getMissionId() {
		return missionId;
	}

	public void setState(boolean isFirst) {
		this.isFirst = isFirst;
	}
}
